package com.graduation.smartparkingplatform.Controller;

import com.graduation.smartparkingplatform.Response.Response;
import com.graduation.smartparkingplatform.Response.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/Railing")
public class RailingController {
  @Autowired RedisTemplate redisTemplate;

  // 修改栏杆状态（进）
  @PostMapping("/RailingIn")
  public Response RailingIn(@RequestParam("status") Boolean status) {
    try {
      if (status) {
        redisTemplate.opsForValue().set("Railing_in", "sys_open");
      } else {
        redisTemplate.opsForValue().set("Railing_in", "sys_close");
      }
      return ResponseUtils.buildSuccess();
    } catch (Exception e) {
      return ResponseUtils.buildError(e);
    }
  }

  // 修改栏杆状态（出）
  @PostMapping("/RailingOut")
  public Response RailingOut(@RequestParam("status") Boolean status) {
    try {
      if (status) {
        redisTemplate.opsForValue().set("Railing_out", "sys_open");
      } else {
        redisTemplate.opsForValue().set("Railing_out", "sys_close");
      }
      return ResponseUtils.buildSuccess();
    } catch (Exception e) {
      return ResponseUtils.buildError(e);
    }
  }
}
